
import { Provide, Inject } from '@midwayjs/core';
import { MajorDao } from '@dao/major.dao';
import { CreateMajorDto, UpdateMajorDto, QueryMajorDto } from '@dto/major.dto';
import { DownloadExcelService } from '../service/common/downloadExcel';
@Provide()
export class MajorService {
  @Inject()
  majorDao: MajorDao;
  @Inject()
  downloadExcelService: DownloadExcelService;
   // 创建
  async create(body: CreateMajorDto) {
    return await this.majorDao.create(body);
  }
  // 获取列表
  async list(query: QueryMajorDto) {
    return await this.majorDao.list(query);
  }

  // 根据年级ID获取专业列表
  async listByGrade(gradeId: number) {
    return await this.majorDao.listByGrade(gradeId);
  }

  // 获取学院年级列表
  async getGradeList() {
    return await this.majorDao.getGradeList();
  }
  // 获取详情
  async detail(majorId: string) {
    return await this.majorDao.detail(+majorId);
  }
  // 修改
  async update( body: UpdateMajorDto) {
    return await this.majorDao.update(body);
  }
  // 删除
  async remove(majorIds: Array<number>) {
    return await this.majorDao.remove(majorIds);
  }
  // 导出
  async export(queryParams: QueryMajorDto) {
    const headers = [
      { label: '专业ID', prop: 'majorId' },
      { label: '年级ID', prop: 'gradeId' },
      { label: '专业名称', prop: 'majorName' },
      { label: '年级专业名称', prop: 'gradeMajorName' },
      { label: '状态（0未分组 1已分组）', prop: 'groupFlag' },
      { label: '备注', prop: 'remark' },
      { label: '状态（0正常 1停用）', prop: 'status' }
    ];
    const { rows } = (await this.majorDao.list(queryParams)).data;
    return this.downloadExcelService.downloadExcel({
      headers,
      data: rows,
      sheetName: 'Major信息',
    });
  }
}
